$(document).ready(function () {
    let deviceWidth = document.body.clientWidth
    // 页面区分参数
    let key = new URLSearchParams(location.search).get('key')
    let clound = location.pathname.includes('cdn') || ''
    var domTop = {}
    var topTime = ''
    var headerHeight = 0
    $('.platform-box').css('opacity', 1)
    //页面显示过度动画插件
    new WOW().init()
    // 顶部轮播图
    var platformSwiper = new Swiper(".platform-banner-swiper", {
        navigation: {
            nextEl: '.swiper-button-prev',
            prevEl: '.swiper-button-next',
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    });
    setTimeout(() => {
        setDomTop()
    }, 800);
    // 导航栏处理
    // 导航栏点击事件
    $('.nav-list li').each(function () {
        let _this = this
        let flexHeight = $(_this).outerHeight() * 1
        let id = $(_this).data('id')
        if (!id) {
            return
        }
        $(_this).on('click', function (e) {
            // 云加速-联系我们
            if (!id.includes('#')) {
                // location.href = location.origin +'/xiaxin' + id
                location.href = location.origin + id
                window.reload(true)
                return
            }
            console.log('nav点击', domTop);
            clearTimeout(topTime)
            topTime = setTimeout(() => {
                $("html, body").animate({ scrollTop: domTop[id] - flexHeight - headerHeight }, 400);
            }, 100);
        })
    })
    // 导航栏点击事件——移动端
    if (deviceWidth < 1400) {
        $('.nav-list').on('click', function () {
            console.log('点击');
            if (!$(this).hasClass('nav-show-list')) {
                $(this).addClass('nav-show-list')
                return
            }
            $(this).removeClass('nav-show-list')
        })
    }
    //导航栏点击事件-统计滚动和处理二级页面显示
    function setDomTop() {
        let keys = clound ? ['#platform-clound', '#platform-clound-appli'] : ['#platform-product', '#platform-plan']
        keys.forEach((key) => {
            domTop[key] = ($(`${key}`).offset().top * 1).toFixed(2)
        })
        headerHeight = $('.header-box').outerHeight() * 1
    }
    if (key !== 'safety') {
        var exampleSwiper = new Swiper(".platform-example-swiper", {
            slidesPerView: "auto",
            spaceBetween: deviceWidth > 768 ? 50 : 20,
        });
        var planSwiper = new Swiper(".plan-list-swiper", {
            on: {
                slideChange: function () {
                    var swiper = this;
                    console.log(swiper.activeIndex);
                    $('.plan-nav-list li').each(function () {
                        let id = $(this).data('id') * 1 - 1
                        $(this).removeClass('plan-active')
                        if (swiper.activeIndex === id) {
                            $(this).addClass('plan-active')
                        }
                    })
                }
            }
        });

        $('.plan-nav-list li').each(function () {
            $(this).on('click', function () {
                let id = $(this).data('id') * 1 - 1
                if (planSwiper) {
                    planSwiper.slideTo(id)
                }
            })
        })
    }
    // 处理显示和隐藏
    if (clound) {
        $('.appli-item').each(function () {
            $(this).on('click', function () {
                $(this).siblings().removeClass('appli-show-item')
                $(this).addClass('appli-show-item')
            })
        })
    }
})